package com.example.testing.ipcdemo;

import android.os.Parcel;
import android.os.Parcelable;

/**
 * Created by tangjiangxu on 9/4/17.
 */

public class ParcelableInfo implements Parcelable {


    public int userId;
    public String userName;
    public boolean isMale;
    public Book book;

    public ParcelableInfo(int userId, String userName, boolean isMale) {
        this.userId = userId;
        this.userName = userName;
        this.isMale = isMale;
    }

    protected ParcelableInfo(Parcel in) {
        userId = in.readInt();
        userName = in.readString();
        isMale = in.readInt() == 1;
        book = in.readParcelable(Thread.currentThread().getContextClassLoader());
    }

    public static final Creator<ParcelableInfo> CREATOR = new Creator<ParcelableInfo>() {
        @Override
        public ParcelableInfo createFromParcel(Parcel in) {
            return new ParcelableInfo(in);
        }

        @Override
        public ParcelableInfo[] newArray(int size) {
            return new ParcelableInfo[size];
        }
    };

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel out, int flags) {
        out.writeInt(userId);
        out.writeString(userName);
        out.writeInt(isMale ? 1 : 0);
        out.writeParcelable(book, 0);

    }
}
